﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

namespace QuaManSys
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                //获取登录用户的账号和密码
                string strName = txtName.Text;
                string strPwd = txtPwd.Text;

                //在entities查找当前用户的信息
                QuaManSysEntities context = new QuaManSysEntities();
                var query = from c in context.Tab_Person
                            where c.employeeId == strName
                            select c;
                //var query = from Tab_Person in dc.GetTable<Tab_Person>()
                //            where Tab_Person.employeeId == strName
                

                //匹配用户信息
                foreach (var person in query)
                {
                    if (strPwd.Equals(person.password.ToString().Trim()))
                    {
                        Session.Add("curUser", person);
                        Response.Redirect("MainPage.aspx");
                        
                    }
                    else
                    {
                        Response.Write("<Script>alert('用户名或密码错误，请重试！');</Script>");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw ex;
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtName.Text = "";
            txtPwd.Text = "";
        }
    }
}